package com.example.lenovo.test1;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.widget.LinearLayout;

public class MainActivity extends AppCompatActivity {
    //定义全局变量
    private LinearLayout mFuLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }
    private  void initView(){
        //初始化父容器
        mFuLayout = findViewById(R.id.fu_layout);
        //设置父容器方向
        //mFuLayout.setOrientation(LinearLayout.HORIZONTAL);
        //创建left子容器 1
        LinearLayout leftLayout = new LinearLayout(this);
        //给子容器设置宽，高比重为1
        leftLayout.setLayoutParams(new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,1));
        //给子容器设置背景颜色
        leftLayout.setBackgroundColor(Color.RED);
        //父容器添加子容器
        mFuLayout.addView(leftLayout);

        LinearLayout rightLayout = new LinearLayout(this);

        rightLayout.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT,2));

        rightLayout.setBackgroundColor(Color.BLUE);

        mFuLayout.addView(rightLayout);
    }
}
